import Vue from 'vue'
import Vuex from 'vuex'
import users from './users'
import counter from './counter'
import product from './modules/product'
import cart from './modules/cart'
Vue.use(Vuex)

export default new Vuex.Store({
  // state: {
  //   count: 0,
  //   users: [],
  //   user: {}
  // },
  // mutations: {
  //   increment(state) {
  //     state.count++;
  //   },
  //   decrement(state) {
  //     state.count--;
  //   },
  //   load(state, payload) {
  //     state.users = payload
  //   },
  //   setUser(state, payload) {
  //     state.user = payload
  //   }
  // },
  // actions: {
  //   increment: ({ commit }) => commit("increment"),
  //   decrement: ({ commit }) => commit("decrement"),
  //   load: async ({ commit }) => {
  //     const response = await fetch("https://www.fastmock.site/mock/a9b15cd4db90d4e03ed76cd3c76d9197/f6/users");
  //     const responseJson = await response.json();
  //     console.log(responseJson)
  //     commit("load", await responseJson.data.users);
  //   },
  //   login: async ({ commit }, param) => {
  //     const response = await fetch("https://www.fastmock.site/mock/a9b15cd4db90d4e03ed76cd3c76d9197/f6/login",
  //       {
  //         method: 'post',
  //         body: {
  //           username: param.username,
  //           password: param.password
  //         }

  //       }

  //     )
  //     const responseJosn = await response.json()
  //     console.log(responseJosn)
  //     if (responseJosn.success) {
  //       commit("setUser", responseJosn.data)
  //     }
  //   }
  // },
  // getters: {
  //   evenOrOdd: state => (state.count % 2 === 0 ? "偶数" : "奇数"),
  //   filters: state =>(state.users.splice(0,2))
  // },
  modules: {
    users:users,
    count:counter,
    product:product,
    cart:cart
  }
})
